package org.presence.dao.impl;

import java.util.Date;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.presence.dao.QuizzDao;
import org.presence.hibernate.Cours;
import org.presence.hibernate.Etudiants;
import org.presence.hibernate.Quizz;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class QuizzDaoImpl extends HibernateDaoSupport implements QuizzDao{

	@Override
	public void addQuizz(Quizz e) {
		if (null == e) {
			throw new IllegalArgumentException(
					"Login and password are mandatory. Null values are forbidden.");
		}
		try {
			HibernateTemplate template= getHibernateTemplate();
			logger.debug(template);
			template.save(e);
			
		} catch (DataAccessException ex) {
			// Critical errors : database unreachable, etc.
			logger.error("Exception - DataAccessException occurs : "
					+ ex.getMessage() + " on complete checkLogin().");
		}
		
	}

	@Override
	public void addQuizzes(List<Quizz> l) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Quizz findQuizzById(Quizz e) {
		if (null == e) {
			throw new IllegalArgumentException(
					"Login and password are mandatory. Null values are forbidden.");
		}
		try {
			logger.info("Check Etudiant with id: " + e.getId());
			return (Quizz) getHibernateTemplate().load(Quizz.class,
					new Integer(e.getId()));
		} catch (DataAccessException ex) {
			// Critical errors : database unreachable, etc.
			logger.error("Exception - DataAccessException occurs : "
					+ ex.getMessage() + " on complete checkLogin().");
		}
		return null;
	}

	@Override
	public List<Quizz> listQuizz() {
		try {
			logger.info("Retrieveing etudiants");
			return (List<Quizz>) getHibernateTemplate()
					.findByCriteria(
							DetachedCriteria.forClass(Quizz.class)
									.addOrder(Order.asc("nom")));
		} catch (DataAccessException ex) {
			// Critical errors : database unreachable, etc.
			logger.error("Exception - DataAccessException occurs : "
					+ ex.getMessage() + " on complete checkLogin().");
		}
		return null;
	}

	@Override
	public void removeQuizz(Quizz e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void removeQuizz(List<Quizz> l) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void updateQuizz(Quizz e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void updateQuizz(List<Quizz> l) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<Quizz> findQuizzBetween(Date debut, Date fin) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Quizz> findQuizzByCours(Cours cours) {
		// TODO Auto-generated method stub
		return null;
	}

}
